#!/usr/bin/python
# -*- coding: utf-8 -*-

import maya.cmds as mc
import maya.mel as mel

import bodyTemple_build
reload(bodyTemple_build)

import Seketon_build
reload(Seketon_build)

import LZ_realistBodySys_baseSetting_builder
reload(LZ_realistBodySys_baseSetting_builder)


class LZ_realistBodySys_UI(bodyTemple_build.LZ_realistBodySys_templeBuilder, Seketon_build.LZ_realistBodySys_SeketonBuilder , LZ_realistBodySys_baseSetting_builder.LZ_realistBodySys_baseSetting_builder):
    
    def __init__(self):
    
        Seketon_build.LZ_realistBodySys_SeketonBuilder.__init__(self)
    
    def LZ_realistBodySys_Win(self):
        LZ_realistBodySys_Win = 'LZ_realistBodySys'
        if mc.window(LZ_realistBodySys_Win,ex = True):
            mc.deleteUI(LZ_realistBodySys_Win)
            
        mc.window(LZ_realistBodySys_Win,widthHeight=(250, 400),t='LZ_Tools_v1.05',menuBar = True,rtf=True,s=True)
     
        
        
        main = mc.columnLayout('LZ_realistBodySys_main',columnAttach=('both', 5), rowSpacing=10, columnWidth=250 )
        
        mc.textField('charactorField' )
        
        mc.button('create_Temple',c = lambda *args:self.create_Temple() )
        
        #mc.rowLayout('mirrorLocTemple_rowLY',numberOfColumns=2,columnWidth2=(100, 100), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0)])
        
        mc.radioButtonGrp( 'mirrorTempleLoc_RBG',label='mirrror :',columnWidth5 = [ 50,5,50,5,50], labelArray2=['L >> R', 'R >> L'], numberOfRadioButtons=2 ,sl = 1 )
        mc.radioButtonGrp( 'mirrorTempleLoc_RBG',e=True,columnWidth = [1,50]  )
        
        mc.button('mirrorTempleLoc' , c = lambda *args:self.mirrorTemple() )
        
        #mc.setParent( 'LZ_realistBodySys_main' )
        mc.button('build_skeleton',c = lambda *args:self.build_skeleton() )
        mc.button('build_rig_setting',c = lambda *args:self.build_rig_setting() )
        
        
        
        mc.showWindow()
        
        
        
    def create_Temple(self):
        self.LZ_realistBodySys_createTemple()
        self.mirrorTempleLocator ( direction = 'L')
        
    def mirrorTemple(self):
        
        direction = mc.radioButtonGrp( 'mirrorTempleLoc_RBG',q=True,sl=True)
        mirror = 'L_'
        if direction == 1 :
            mirror = 'L'
        else:
            mirror = 'R'
        print( mirror )
        self.mirrorTempleLocator (direction = mirror )
        print('ok')
        
    def build_skeleton(self):
        self.LZ_realistBodySys_createBaseJnt()
        
    def build_rig_setting(self):
    
        charactor = mc.textField('charactorField',q=True,text=True )
    
        self.LZ_realistBodySys_baseSetting_Spine()
        L_armGrp = self.LZ_realistBodySys_baseSetting_Arm(armSkeleton =  ['Rbs_L_arm_skeleton','Rbs_L_foreArm_skeleton','Rbs_L_hand_skeleton'],clavicle = 'Rbs_L_clavicle_skeleton',ctrlOrientReference='Rbs_L_hand_Temple' )

        R_armGrp = self.LZ_realistBodySys_baseSetting_Arm( armSkeleton =  ['Rbs_R_arm_skeleton','Rbs_R_foreArm_skeleton','Rbs_R_hand_skeleton'],clavicle = 'Rbs_R_clavicle_skeleton',ctrlOrientReference='Rbs_R_hand_Temple' )
        L_legGrp = self.LZ_realistBodySys_baseSetting_Arm( armSkeleton =  ['Rbs_L_upleg_skeleton','Rbs_L_leg_skeleton','Rbs_L_foot_skeleton']  ,clavicle = 'Rbs_hip_Dn_skeleton',ctrlOrientReference='Rbs_L_ankle_skeleton' )
        R_legGrp = self.LZ_realistBodySys_baseSetting_Arm( armSkeleton =  ['Rbs_R_upleg_skeleton','Rbs_R_leg_skeleton','Rbs_R_foot_skeleton']  ,clavicle = 'Rbs_hip_Dn_skeleton',ctrlOrientReference='Rbs_R_ankle_skeleton' )
        
        L_aclavicleGrp = self.LZ_realistBodySys_baseSetting_clavicle(clavicleSkeleton = [ 'Rbs_R_shoulder_skeleton','Rbs_R_clavicle_skeleton','Rbs_R_arm_skeleton' ] ,centergrp = 'Rbs_chest_skeleton')
        R_aclavicleGrp = self.LZ_realistBodySys_baseSetting_clavicle(clavicleSkeleton = [ 'Rbs_L_shoulder_skeleton','Rbs_L_clavicle_skeleton','Rbs_L_arm_skeleton' ] ,centergrp = 'Rbs_chest_skeleton')
        
        
        all_ctrl = self.LZ_realistBodySys_baseSetting_globalGrp( charactorName = charactor )
        '''
        =========================================================
        ||                                                     ||
        ||合并设置                                             ||
        ||combine settings                                     ||
        ||                                                     ||
        =========================================================
        '''
        legFollowGrp = 'hip_state_grp'
        shouldFollowGrp = 'chest_state_grp'
        L_armFolloGrp = 'L_clavicle_state_grp'
        R_armFolloGrp = 'R_clavicle_state_grp'
        
        for followGrp in [ (legFollowGrp,'hipEnd_jnt',[L_legGrp,R_legGrp]),(shouldFollowGrp,'chest_jnt' , [L_aclavicleGrp,R_aclavicleGrp]),(L_armFolloGrp,'L_clavicle_jnt' , [L_armGrp]),(R_armFolloGrp,'R_clavicle_jnt' , [R_armGrp]) ]:
            mc.group( em=True, n = followGrp[0] )
            mc.parent( followGrp[0] , followGrp[1] )
            self.clear_channelBox_Transform( obj= followGrp[0] )
            
            for grp  in followGrp[2] :
                print(followGrp[2] )
                mc.parentConstraint( followGrp[0] , grp, mo=True )
        
        
        mc.parent('hip_mcap' , L_armGrp , R_armGrp , L_legGrp , R_legGrp , L_aclavicleGrp,R_aclavicleGrp,  all_ctrl[0] )
        
        
        
        